﻿using System.Collections.Generic;
using UnityEngine;

public enum EnemyTransition
{
    NullTransition = 0,
    CanAttack,
    LostSoldier,
}

public enum EnemyStateId
{
    NullStateId,
    Chase,
    Attack,
}

public abstract class IEnemyState
{
    protected Dictionary<EnemyTransition, EnemyStateId> mMap = new Dictionary<EnemyTransition, EnemyStateId>();
    protected EnemyStateId mStateId;
    protected ICharacter mCharacter;
    protected EnemyFSMSystem mFSM;
    public EnemyStateId StateId => mStateId;

    public IEnemyState(EnemyFSMSystem fsm, ICharacter character)
    {
        mFSM = fsm;
        mCharacter = character;
    }

    public void AddTransition(EnemyTransition trans, EnemyStateId id)
    {
        if (trans == EnemyTransition.NullTransition)
        {
            Debug.LogError("EnemyTransition 为空!");
            return;
        }

        if (id == EnemyStateId.NullStateId)
        {
            Debug.LogError("EnemyStateId为空!");
            return;
        }

        if (mMap.ContainsKey(trans))
        {
            Debug.LogError("包含该EnemyTransition，请勿重复添加");
            return;
        }

        mMap.Add(trans, id);
    }

    public void DeleteTransition(EnemyTransition trans)
    {
        if (trans == EnemyTransition.NullTransition)
        {
            Debug.LogError("EnemyTransition 为空");
            return;
        }

        if (mMap.ContainsKey(trans))
        {
            mMap.Remove(trans);
            return;
        }

        Debug.LogError("错误：删除EnemyTransition时出现错误!");
    }

    public EnemyStateId GetOutputState(EnemyTransition trans)
    {
        if (mMap.ContainsKey(trans))
        {
            return mMap[trans];
        }

        return EnemyStateId.NullStateId;
    }

    public virtual void DoBeforeEntering()
    {
    }

    public virtual void DoBeforeLeaving()
    {
    }

    public abstract void Reasoning(List<ICharacter> targets);
    public abstract void Actioning(List<ICharacter> targets);
}